﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;
namespace Evan.WebUI
{
    /// <summary>
    /// Ajax通用基类 - 管理员专用  注意 ProcessRequest 为虚方法 , 需要重写
    /// </summary>
    public class ManagerAshxHelper : IHttpHandler, IRequiresSessionState
    {
        /// <summary>
        /// 全局配置信息
        /// </summary>
        public Model.SysModel.GlobalConfigModel GlobalConfigModel = new Model.SysModel.GlobalConfigModel();
        /// <summary>
        /// 站点配置信息
        /// </summary>
        public dynamic SiteConfig = Common.SysComm.GetSiteConfig();
        /// <summary>
        /// 当前请求的页面(含目录)
        /// </summary>
        public string requestPath = HttpContext.Current.Request.Path.ToLower();

        /// <summary>
        /// 是否有权限  , 默认为false
        /// </summary>
        public bool HasRole = false;

        /// <summary>
        /// 虚方法重写即可  不可在此写逻辑代码
        /// </summary>
        /// <param name="context"></param>
        public virtual void ProcessRequest(HttpContext context)
        {
            //此处禁止写任何东西
        }

        /// <summary>
        /// 去除 上传上来的Json后面带的乱七八糟  暂时这样
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        protected string GetParam(string Name)
        {
            if (string.IsNullOrEmpty(Evan.Common.CommFun.GetParams(Name)))
            {
                return "";
            }
            //Evan.SystemLog.MemLog.AddExLog("GetParam方法获取的值", null, Evan.Common.CommFun.GetParams(Name));
            return Evan.Common.CommFun.GetParams(Name).Replace(",[object Object]", "");
        }


        /// <summary>
        /// 输出json结果 返回2个值 result (输出succes的值)   returnval (输出str的值)
        /// </summary>
        /// <param name="context"></param>
        /// <param name="success">是否操作成功,0表示失败;1表示成功</param>
        /// <param name="str">输出字符串</param>
        protected void JsonResult(HttpContext context, int success, string str)
        {
            context.Response.Write("{\"result\" :\"" + success.ToString() + "\",\"returnval\" :\"" + str + "\"}");
            context.Response.End();
        }
        /// <summary>
        /// 输出json结果 返回2个值 result (输出succes的值)   returnval (输出str的json字符串)
        /// </summary>
        /// <param name="context"></param>
        /// <param name="success">是否操作成功,0表示失败;1表示成功</param>
        /// <param name="str">输出json对象</param>
        protected void JsonResult2(HttpContext context, int success, string str)
        {
            context.Response.Write("{\"result\" :\"" + success.ToString() + "\",\"returnval\" :" + str + "}");
            context.Response.End();
        }
        /// <summary>
        /// 输出 Model Json
        /// </summary>
        /// <param name="context"></param>
        /// <param name="model">输出一个model的json</param>
        protected void JsonResult(HttpContext context, dynamic model)
        {
            string json = Evan.Model.ConvertModel.ConvertToJson(model);
            context.Response.Write(json);
            context.Response.End();
        }

       /// <summary>
        /// 验证权限
       /// </summary>
       /// <param name="context"></param>
       /// <param name="HasRole">是否有权限</param>
        public void VerifyRoles(HttpContext context ,bool HasRole = false)
        {
            if (!HasRole)
            {
                //如果没有权限  // 则回来做相应处理
                if (requestPath.EndsWith(".aspx"))
                {
                    HttpContext.Current.Response.Redirect(SiteConfig.WebAdminPath + "roles.aspx" + "?from=" + Common.CommFun.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri));
                }
                else if (requestPath.EndsWith(".ashx"))
                {
                    JsonResult(context, -100, "权限不足 !");
                }
            }
        }

        /// <summary>
        /// 返回是否有权限
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="table">表</param>
        /// <param name="RoleType">权限类型 增删改查</param>
        /// <param name="ClassId">栏目ID , 系统类型可以不用ClassId</param>
        /// <returns></returns>
        public bool ReturnHasRole(HttpContext context, string table, string RoleType, string ClassId)
        {

            //系统表
            string[] SysTab = { "module", "channel", "roles", "statistic", "systemlog", "versions", "administrator", "areas", "fields", "process", "template" };
            string[] SysRole = { "module", "channel", "role", "statistic", "syslog", "system", "admin", "area", "field", "process", "template" };
            if (SysTab.Contains(table.ToLower()))
            {
                //系统位置
                int _i = 0;
                for (int i = 0; i < SysTab.Length; i++)
                {
                    if (SysTab[i] == table.ToLower())
                    {
                        _i = i;
                        continue;
                    }
                }
                HasRole = Member.Administrator.HasRole(0, "0", SysRole[_i], "");
            }
            else
            {
                //其余位置 , 按照classid判断
                if (!string.IsNullOrEmpty(ClassId))
                {
                    HasRole = Member.Administrator.HasRole(1, ClassId, "", RoleType);
                }

            }
            return HasRole;
        }

        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected int AddFields(HttpContext context)
        {
            dynamic model = Model.ConvertModel.ConvertToDynamic(GetParam("model"));
            string table = GetParam("table");
            //拿到classid 用classid获取栏目信息 获取pagetype 获取表名称
            string classid = model.ClassId;
            dynamic channel = new DataBase.DbOperat("Channel").GetModel(int.Parse(classid));
            string channel_tablename = Evan.Template.TemplateHelper.GetTableNameByPageType(Convert.ToInt32(channel.PageType));
            //如果拿到的表名称是空的 那就返回错误
            if (string.IsNullOrEmpty(channel_tablename))
            {
                return -3;
            }
            //先检查字段名是否存在
            DataBase.DbOperat Db = new DataBase.DbOperat(channel_tablename);
            bool isExist = Db.IsExistField(model.FieldName);
            if (!isExist)
            {
                //不存在开始添加  添加分两步  1 添加一行数据到field表  2 添加字段到对应表
                Model.SysModel.FieldModel FieldModel = Model.ConvertModel.ConvertToFieldModel(model, channel_tablename);
                bool IsOk = Db.AddFieldToTable(FieldModel);
                if (IsOk)
                {
                    
                    model.Set("AddUser", GetAdminId());
                    model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                    //model.Set("FieldVerify", model.FieldVerify.ToString().Trim(','));
                    return Db.InsertReturnId(model, table);
                }
                else
                {
                    return -2;
                }
            }
            else
            {
                try
                {
                    //如果存在当前字段  如果是处于被删除的状态下  那就激活这个字段 并更新当前的属性值到该表
                    dynamic field = new DataBase.DbOperat(table).GetModel_1("ClassId=" + classid + " and FieldName='" + model.FieldName + "'");
                    if (field == null)
                    {
                        model.Set("AddUser", GetAdminId());
                        model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                        return Db.InsertReturnId(model, table);
                    }
                    else
                    {
                        //不为空 说明是被锁定后修改
                        model.Set("Id", field.Id);
                        model.Set("States", "1");
                        model.Set("AddUser", GetAdminId());
                        model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                        bool isok = UpdateModel(table, model);
                        SystemLog.MemLog.AddExLog2("已经存在字段 , 需将字段显示并重新赋值", null, "操作状态 : " + isok.ToString());
                        return isok ? 1 : 0;
                        
                    }
                }
                catch (Exception ex)
                {
                    Evan.SystemLog.MemLog.AddExLog2("添加字段失败 , 调用方法名 : " + ex.TargetSite.Name, null, ex.ToString());
                    return -1;
                }
            }
        }

        /// <summary>
        /// 添加 获取默认 model 和 table 参数
        /// </summary>
        /// <param name="context"></param>
        /// <returns>返回添加的ID</returns>
        protected int AddModel(HttpContext context)
        {
            dynamic model = Model.ConvertModel.ConvertToDynamic(GetParam("model"));
            model.Set("AddUser", GetAdminId());
            if (!Evan.Model.ConvertModel.HasKey(model, "AddTime"))
            {
                model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            }

            //检查是否有密码
            if (Evan.Model.ConvertModel.HasKey(model, "UserPwd"))
            {
                model.Set("UserPwd", Evan.Common.CommFun.EnPwd(model.UserPwd));
            }

            string table = GetParam("table");
            //Evan.Common.CommFun.WirteFile("CopyChannelTable:" + table + "");
            int IsOk = new DataBase.DbOperat(table).InsertReturnId(model);
            if (IsOk > 0)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 添加 [" + model.Title + "] 成功", "添加成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [标题=" + model.Title + "] ", model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 添加 [" + model.Title + "] 失败", "添加失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [标题=" + model.Title + "] ", model);
            }
            return IsOk;
        }

        /// <summary>
        /// 添加 获取默认 model 和 table 参数
        /// </summary>
        /// <param name="context"></param>
        /// <param name="Model"></param>
        /// <returns>返回添加的ID</returns>
        protected int AddModel(HttpContext context, dynamic Model)
        {
            string table = GetParam("table");
            Model.Set("AddUser", GetAdminId());
            if (!Evan.Model.ConvertModel.HasKey(Model, "AddTime"))
            {
                Model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            }
            //检查是否有密码
            if (Evan.Model.ConvertModel.HasKey(Model, "UserPwd"))
            {
                Model.Set("UserPwd", Evan.Common.CommFun.EnPwd(Model.UserPwd));
            }
            int IsOk = new DataBase.DbOperat(table).InsertReturnId(Model);
            if (IsOk>0)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 添加 [" + Model.Title + "] 成功", "添加成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [标题=" + Model.Title + "] ", Model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 添加 [" + Model.Title + "] 失败", "添加失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [标题=" + Model.Title + "] ", Model);
            }
            return IsOk;
        }

        /// <summary>
        /// 更新 获取默认 model 和 table 参数
        /// </summary>
        /// <param name="context"></param>
        /// <returns>返回是否成功</returns>
        protected bool UpdateModel(HttpContext context)
        {
            dynamic model = Model.ConvertModel.ConvertToDynamic(GetParam("model"));
            if (Evan.Model.ConvertModel.HasKey(model, "UserPwd"))//检查是否有密码
            {
                model.Set("UserPwd", Evan.Common.CommFun.EnPwd(model.UserPwd));
            }
            model.Set("EditUser", GetAdminId());
            model.Set("EditTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            string table = GetParam("table");
            bool IsOk = new DataBase.DbOperat(table).Update(model);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新 [" + model.Title + "] 成功", "更新成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [标题=" + model.Title + "] ", model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新 [" + model.Title + "] 失败", "更新失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [标题=" + model.Title + "] ", model);
            }
            return IsOk;
        }

        /// <summary>
        /// 更新 获取默认 model 和 table 参数
        /// </summary>
        /// <param name="context"></param>
        /// <param name="Model">传入的更新Model</param>
        /// <returns>返回是否成功</returns>
        protected bool UpdateModel(HttpContext context, dynamic Model)
        {
            string table = GetParam("table");
            if (Evan.Model.ConvertModel.HasKey(Model, "UserPwd"))//检查是否有密码
            {
                Model.Set("UserPwd", Evan.Common.CommFun.EnPwd(Model.UserPwd));
            }
            Model.Set("EditUser", GetAdminId());
            Model.Set("EditTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            bool IsOk = new DataBase.DbOperat(table).Update(Model);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新 [" + Model.Title + "] 成功", "更新成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [内容=" + Model.Title + "]  [ID=" + Model.Id + "] ", Model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新 [" + Model.Title + "] 失败", "更新失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [内容=" + Model.Title + "]  [ID=" + Model.Id + "] ", Model);
            }
            return IsOk;
        }
        /// <summary>
        /// 更新 指定 model 和 table 参数
        /// 不需要 context 后面逐渐改为不依赖 context  2019年6月27日14:43:02
        /// </summary>
        /// <param name="table">表名称</param>
        /// <param name="Model">传入的更新Model</param>
        /// <returns></returns>
        protected bool UpdateModel(string table, dynamic Model)
        {
            //string table = GetParam("table");
            Model.Set("EditUser", GetAdminId());
            Model.Set("EditTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            bool IsOk = new DataBase.DbOperat(table).Update(Model);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新 [" + Model.Title + "] 成功", "更新成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [内容=" + Model.Title + "]  [ID=" + Model.Id + "] ", Model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新 [" + Model.Title + "] 失败", "更新失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [内容=" + Model.Title + "]  [ID=" + Model.Id + "] ", Model);
            }
            return IsOk;
        }


        #region 管理员添加编辑操作
        /// <summary>
        /// 添加 管理员
        /// </summary>
        /// <param name="context"></param>
        /// <param name="Model"></param>
        /// <returns>返回添加的ID</returns>
        protected int AddAdministrator(HttpContext context, dynamic Model)
        {
            string table = GetParam("table");
            Model.Set("AddUser", GetAdminId());
            if (!Evan.Model.ConvertModel.HasKey(Model, "AddTime"))
            {
                Model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            }
            int IsOk = new DataBase.DbOperat(table).InsertReturnId(Model);
            if (IsOk > 0)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 添加管理员信息 [" + Model.Name + "] 成功", "添加成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [名称=" + Model.Name + "] ", Model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 添加管理员信息 [" + Model.Name + "] 失败", "添加失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [名称=" + Model.Name + "] ", Model);
            }
            return IsOk;
        }

        /// <summary>
        /// 更新 管理员
        /// </summary>
        /// <param name="context"></param>
        /// <param name="Model">传入的更新Model</param>
        /// <returns>返回是否成功</returns>
        protected bool UpdateAdministrator(HttpContext context, dynamic Model)
        {
            string table = GetParam("table");
            Model.Set("EditUser", GetAdminId());
            Model.Set("EditTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            Model.Set("LastRePwdTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            bool IsOk = new DataBase.DbOperat(table).Update(Model);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新管理员信息 [" + Model.Name + "] 成功", "更新成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [内容=" + Model.Name + "]  [ID=" + Model.Id + "] ", Model);
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 更新管理员信息 [" + Model.Name + "] 失败", "更新失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [内容=" + Model.Name + "]  [ID=" + Model.Id + "] ", Model);
            }
            return IsOk;
        }

        /// <summary>
        /// 查看管理员是否为空
        /// 添加/修改管理员的时候 都需要检查登录名是否有重复
        /// <para>添加的时候务必填写参数 ,否则Id为空会报错</para>
        /// </summary>
        /// <param name="Model">管理员</param>
        /// <param name="IsAdd">是否添加 , 默认不添加</param>
        /// <returns>返回是否存在管理员 true=存在 , false=不存在</returns>
        protected bool CheckHasAdmin(dynamic Model, bool IsAdd = false)
        {
            dynamic AdminModel = new Evan.Model.DynamicModel();
            if (IsAdd)
            {
                AdminModel = new Evan.DataBase.DbOperat("Administrator").GetModel_1("Name=@Name and States>-1", Model.Name);
            }
            else
            {
                AdminModel = new Evan.DataBase.DbOperat("Administrator").GetModel_1("Name=@Name and Id<>@Id and States>-1", Model.Name, Model.Id);
            }
            //new Evan.DataBase.DbOperat("Administrator").GetModel_1("Name=@Name " + (IsAdd ? "" : "and Id<>@Id") + " and States>-1", Model.Name, Model.Id);
            if (AdminModel == null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        
        #region 快捷操作 States设置状态
        /// <summary>
        /// 
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool SetState(HttpContext content)
        {
            string table = GetParam("table");
            string states = GetParam("states");
            string id = GetParam("id");
            #region 如果操作的是组件的话 权限和表使用模板的
            if (table.ToLower() == "Component".ToLower())
            {
                table = "Template";
            }
            #endregion
            bool IsOk = new DataBase.DbOperat(table).UpdateFields_1("States=@States", "Id=@Id", states, id);
            string operaStr = "";
            switch (states)
            {
                case "-1":
                    operaStr = "删除";
                    break;
                case "0":
                    operaStr = "锁定";
                    break;
                case "1":
                    operaStr = "解锁";
                    break;
                default:
                    operaStr = "未知操作";
                    break;
            }
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] " + operaStr + "信息 [Id=" + id + "] 成功", operaStr + "成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] " + operaStr + "信息 [Id=" + id + "] 失败", operaStr + "失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }
        #endregion

        #region 快捷操作  IsTop置顶/IsIndex首页/IsHot热门/IsRed推荐
        /// <summary>
        /// 置顶操作
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool SetTop(HttpContext content)
        {
            string table = GetParam("table");
            string states = GetParam("states");
            string id = GetParam("id");
            bool IsOk = new DataBase.DbOperat(table).UpdateFields_1("IsTop=@States", "Id=@Id", states, id);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsTop信息 [Id=" + id + "] 成功", "置顶成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsTop信息 [Id=" + id + "] 失败", "置顶失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }
        /// <summary>
        /// 首页操作
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool SetIndex(HttpContext content)
        {
            string table = GetParam("table");
            string states = GetParam("states");
            string id = GetParam("id");
            bool IsOk = new DataBase.DbOperat(table).UpdateFields_1("IsIndex=@States", "Id=@Id", states, id);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsIndex信息 [Id=" + id + "] 成功", "设置IsIndex成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsIndex信息 [Id=" + id + "] 失败", "设置IsIndex失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }
        /// <summary>
        /// 热门操作
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool SetHot(HttpContext content)
        {
            string table = GetParam("table");
            string states = GetParam("states");
            string id = GetParam("id");
            bool IsOk = new DataBase.DbOperat(table).UpdateFields_1("IsHot=@States", "Id=@Id", states, id);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsHot信息 [Id=" + id + "] 成功", "设置IsHot成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsHot信息 [Id=" + id + "] 失败", "设置IsHot失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }
        /// <summary>
        /// 推荐操作
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool SetRed(HttpContext content)
        {
            string table = GetParam("table");
            string states = GetParam("states");
            string id = GetParam("id");
            bool IsOk = new DataBase.DbOperat(table).UpdateFields_1("IsRed=@States", "Id=@Id", states, id);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsRed信息 [Id=" + id + "] 成功", "设置IsRed成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 设置IsRed信息 [Id=" + id + "] 失败", "设置IsRed失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }
        #endregion 

        #region 快捷操作 设置排序Id
        protected bool SetSortId(HttpContext content)
        {
            string table = GetParam("table");
            string sortid = GetParam("sortid");
            string id = GetParam("id");
            return new DataBase.DbOperat(table).UpdateFields_1("SortId=@SortId", "Id=@Id", sortid, id);
        }
        #endregion

        #region 栏目快捷操作箭头排序
        /*2017.08.07 张浩修改，箭头排序值的点击事件*/
        protected bool UpSortId(HttpContext content)
        {
            string table = GetParam("table");
            string sortid = GetParam("sortid");
            string id = GetParam("id");
            string prevsortid = GetParam("prevsortid");
            string previd = GetParam("previd");
            new DataBase.DbOperat(table).UpdateFields_1("SortId=@SortId", "Id=@Id", prevsortid, id);
            return new DataBase.DbOperat(table).UpdateFields_1("SortId=@SortId", "Id=@Id", sortid, previd);
        }
        /*2017.08.07 张浩修改，箭头排序值的点击事件*/
        protected bool DownSortId(HttpContext content)
        {
            string table = GetParam("table");
            string sortid = GetParam("sortid");
            string id = GetParam("id");
            string nextsortid = GetParam("nextsortid");
            string nextid = GetParam("nextid");
            new DataBase.DbOperat(table).UpdateFields_1("SortId=@SortId", "Id=@Id", nextsortid, id);
            return new DataBase.DbOperat(table).UpdateFields_1("SortId=@SortId", "Id=@Id", sortid, nextid);
        }
        #endregion

        #region 回收站操作
        /// <summary>
        /// 物理删除
        /// 从数据库删除
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool RealDel(HttpContext content)
        {
            string table = GetParam("table");
            string id = GetParam("id");
            bool IsOk = new DataBase.DbOperat(table).Delete_1("Id=@Id", id);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 彻底删除信息 [Id=" + id + "] 成功", "彻底删除成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 彻底删除信息 [Id=" + id + "] 失败", "彻底删除失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }
        /// <summary>
        /// 恢复信息
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool Restore(HttpContext content)
        {
            string table = GetParam("table");
            string id = GetParam("id");
            bool IsOk = new DataBase.DbOperat(table).UpdateFields_1("States=1", "Id=@Id", id);
            if (IsOk)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 恢复信息 [Id=" + id + "] 成功", "恢复信息成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 恢复信息 [Id=" + id + "] 失败", "恢复信息失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            }
            return IsOk;
        }


        /// <summary>
        /// 物理删除 - 批量删除
        /// 从数据库删除
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool RealDels(HttpContext content)
        {
            string table = GetParam("table");
            string ids = GetParam("ids");
            int IsOk = new Evan.DataBase.MsSql.DbHelper().ExecteNonQueryText(string.Format("DELETE {0} WHERE Id in ({1})", table, ids), null);
            if (IsOk > 0)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 彻底删除信息 [Id=" + ids + "] 成功", "彻底删除成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + ids + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 彻底删除信息 [Id=" + ids + "] 失败", "彻底删除失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + ids + "] ");
            }
            return IsOk > 0;
        }
        /// <summary>
        /// 恢复信息 - 批量恢复
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool Restores(HttpContext content)
        {
            string table = GetParam("table");
            string ids = GetParam("ids");
            int IsOk = new Evan.DataBase.MsSql.DbHelper().ExecteNonQueryText(string.Format("UPDATE {0} SET States=1 WHERE Id in ({1})", table, ids), null);
            if (IsOk>0)
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 恢复信息 [Id=" + ids + "] 成功", "恢复信息成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + ids + "] ");
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] 恢复信息 [Id=" + ids + "] 失败", "恢复信息失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + ids + "] ");
            }
            return IsOk>0;
        }

        #endregion

        #region 栏目快捷操作 seo/生成/导出/可视化编辑
        /// <summary>
        /// 栏目快捷操作
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected bool ChannelQuickOperat(HttpContext content)
        {
            string states = GetParam("states");
            string id = GetParam("id");
            string operat = GetParam("operat");
            bool IsOk = new DataBase.DbOperat("Channel").UpdateFields_1(operat + "=@" + operat, "Id=@Id", states, id);
            //string operaStr = "";
            //switch (states)
            //{
            //    case "-1":
            //        operaStr = "删除";
            //        break;
            //    case "0":
            //        operaStr = "锁定";
            //        break;
            //    case "1":
            //        operaStr = "解锁";
            //        break;
            //    default:
            //        operaStr = "未知操作";
            //        break;
            //}
            //if (IsOk)
            //{
            //    Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] " + operaStr + "信息 [Id=" + id + "] 成功", operaStr + "成功 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            //}
            //else
            //{
            //    Evan.SystemLog.SysLog.AddSysLog("管理员 [" + Member.Administrator.GetAdminName() + "] " + operaStr + "信息 [Id=" + id + "] 失败", operaStr + "失败 [用户名=" + Member.Administrator.GetAdminName() + "] [表=" + table + "] [ID=" + id + "] ");
            //}
            return IsOk;
        }
        #endregion

        //protected object Delete_Virtual(HttpContext context)
        //{
        //    return null;
        //}




        /// <summary>
        /// 管理员登录是否可以通过 多次破解验证
        /// 不区分登录出错的类型
        /// </summary>
        /// <param name="IsLoginSuccess">是否登录成功 , 登录成功后清除计数器</param>
        /// <returns></returns>
        private bool LoginSecurity(bool IsLoginSuccess)
        {

            string SessionName = Evan.Common.IPHelper.GetHostAddress() + "-" + Evan.Common.CommFun.ReturnSessionID();

            int Count = 0; //登录失败的总次数

            int.TryParse(Evan.Common.CommFun.GetSession(SessionName), out Count);

            SystemLog.MemLog.AddExLog2("登录次数SessionName", null, "计数SessionName" + SessionName.ToString());
            SystemLog.MemLog.AddExLog2("登录次数值", null, "次数为" + Count.ToString());

            bool IsTrue = true; //默认放行

            int Admin_Login_Account_Error = Convert.ToInt32(Evan.Common.CommFun.GetAppSetting("Admin_Login_Error_Count")); //出错机会
            int Admin_Login_Error_Lock_Time = Convert.ToInt32(Evan.Common.CommFun.GetAppSetting("Admin_Login_Error_Lock_Time")) / 60; //锁定多少分钟


            if (Count >= Admin_Login_Account_Error)
            {
                SystemLog.MemLog.AddExLog2("在次数超限后登录成功", null, "登录失败 , 开始计数" + Count.ToString());
                //已经超过次数 即使登录成功也是不能登录的
                IsTrue = false;
                Count = Count + 1;
                Evan.Common.CommFun.AddSession(SessionName, Count.ToString(), Admin_Login_Error_Lock_Time);
                return IsTrue;
            }


            if (IsLoginSuccess)
            {
                SystemLog.MemLog.AddExLog2("登录成功", null, "登录成功 , 清除计数器");
                Evan.Common.CommFun.DelSession(SessionName);
            }
            else
            {
                if (Count >= Admin_Login_Account_Error)
                {
                    SystemLog.MemLog.AddExLog2("登录失败 , 次数超限", null, "登录失败 , 开始计数" + Count.ToString());
                    IsTrue = false;
                    Count = Count + 1;
                    Evan.Common.CommFun.AddSession(SessionName, Count.ToString(), Admin_Login_Error_Lock_Time);
                }
                else {
                    SystemLog.MemLog.AddExLog2("登录失败 , 次数范围内", null, "登录失败 , 开始计数" + Count.ToString());
                    Count = Count + 1;
                    Evan.Common.CommFun.AddSession(SessionName, Count.ToString(), Admin_Login_Error_Lock_Time);
                }
            }

            return IsTrue;
        }

        /// <summary>
        /// 管理员登录 传入参数 name pwd code
        /// </summary>
        /// <param name="context"></param>
        public void AdminLogin(HttpContext context)
        {
            
            string name = Evan.Common.CommFun.GetParams("name");
            string pwd = Evan.Common.CommFun.GetParams("pwd");
            string vcode = Evan.Common.CommFun.GetParams("code");

            //后台是否开启验证码登陆，在Web.Config配置是否开启
            if (Common.CommFun.GetAppSetting("AdminIsVcode") != "1")
            {
                vcode = Common.CommFun.ReadSession("adminlogin").ToString();
            }


            //检查code
            if (Evan.Common.CommFun.ReadSession("adminlogin")==null)
            {
                JsonResult(context, 0, "验证码已过期 , 请重新输入");
            }

            string vcode_server = Evan.Common.CommFun.ReadSession("adminlogin").ToString();

            int Admin_Login_Error_Lock_Time = Convert.ToInt32(Evan.Common.CommFun.GetAppSetting("Admin_Login_Error_Lock_Time")) / 60; //锁定多少分钟

            if (vcode_server.ToUpper() == vcode.ToUpper())
            {

                //获取是否允许管理员多处登录
                bool AllowAdminMultipleLogin = Evan.Common.CommFun.GetAppSetting("AllowAdminMultipleLogin") == "1";
                if (!AllowAdminMultipleLogin)
                {
                    //如果不允许多处登录
                    if (Evan.Member.Administrator.CheckIsLoginByAdminName(name))
                    {
                        //禁止登录
                        Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 当前登录的用户已经从其它设备登录");
                        JsonResult(context, 0, "您的账户已经在其它设备登录");
                    }
                }

                Evan.DataBase.DbOperat db = new Evan.DataBase.DbOperat("Administrator");

                pwd = Evan.Common.CommFun.EnPwd(pwd);

                dynamic model = db.GetModel_1(" Name=@Name and Pwd=@Pwd ", name, pwd);
                if (model != null)
                {
                    if (model.States == 1)
                    {
                        if (LoginSecurity(true))
                        {
                            model.Set("LastLoginIP", Common.IPHelper.GetHostAddress());
                            model.Set("LastLoginTime", DateTime.Now);
                            db.Update(model);
                            Dictionary<string, object> admin = Evan.Model.ConvertModel.ConvertToDictionary(model);
                            Member.Administrator.CacheAdminInfo(admin);
                            Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录成功", "登录成功 [用户名=" + name + "] ");
                            JsonResult(context, 1, "登录成功");
                        }
                        else
                        {
                            Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账户验证成功 , 但是尝试登陆的次数已经超过限制 , 在锁定期仍然尝试登陆");
                            JsonResult(context, 0, "您的登录过于频繁 , 系统已将您的IP锁定 , 请" + Admin_Login_Error_Lock_Time + "分钟后再试");
                        }
                    }
                    else if (model.States == 0)
                    {
                        if (LoginSecurity(false))
                        {
                            Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账户已经被锁定 , 但是尝试登陆 , 并且输入的为正确的账号和密码");
                            JsonResult(context, 0, "您的账户已经被锁定");
                        }
                        else
                        {
                            Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账户已经被锁定 , 但是尝试登陆 , 并且输入的为正确的账号和密码 , 登陆超过限制次数 , 被锁定后仍然尝试登陆");
                            JsonResult(context, 0, "您的登录过于频繁 , 系统已将您的IP锁定 , 请" + Admin_Login_Error_Lock_Time + "分钟后再试");
                        }
                    }
                    else
                    {
                        if (LoginSecurity(false))
                        {
                            Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账户状态异常 , 但是尝试登陆 , 并且输入的为正确的账号和密码 , ");
                            JsonResult(context, 0, "您的账号状态异常");
                        }
                        else
                        {
                            Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账户状态异常 , 但是尝试登陆 , 并且输入的为正确的账号和密码 , 登陆超过限制次数 , 被锁定后仍然尝试登陆");
                            JsonResult(context, 0, "您的登录过于频繁 , 系统已将您的IP锁定 , 请" + Admin_Login_Error_Lock_Time + "分钟后再试");
                        }

                    }
                }
                else
                {
                    if (LoginSecurity(false))
                    {
                        Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账号密码不匹配");
                        JsonResult(context, 0, "账号密码不匹配");
                    }
                    else
                    {
                        Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账号密码不匹配 , 仍然尝试登陆 , 输入的为错误的账号密码 , 登陆已经超过限制次数 , 被锁定后仍然尝试登陆");
                        JsonResult(context, 0, "您的登录过于频繁 , 系统已将您的IP锁定 , 请" + Admin_Login_Error_Lock_Time + "分钟后再试");
                    }

                }
            }
            else
            {
                if (LoginSecurity(false))
                {
                    JsonResult(context, 0, "验证码不正确");
                }
                else
                {
                    JsonResult(context, 0, "您的登录过于频繁 , 系统已将您的IP锁定 , 请" + Admin_Login_Error_Lock_Time + "分钟后再试");
                }
            }
        }

        /// <summary>
        /// 管理员解锁
        /// </summary>
        /// <param name="context"></param>
        public void AdminUnLock(HttpContext context)
        {

            string name = Evan.Member.Administrator.GetAdminName();
            string pwd = Evan.Common.CommFun.GetParams("pwd");
            //检查admin_name
            if (string.IsNullOrEmpty(name))
            {
                JsonResult(context, -2, "登录状态失效 , 请重新登录");
            }
            pwd = Evan.Common.CommFun.EnPwd(pwd);
            //检测密码是否一致
            Evan.DataBase.DbOperat db = new Evan.DataBase.DbOperat("Administrator");
            dynamic model = db.GetModel_1(" Name=@Name and Pwd=@Pwd ", name, pwd);
            if (model != null)
            {
                if (model.States == 1)
                {
                    Dictionary<string, object> admin = Evan.Model.ConvertModel.ConvertToDictionary(model);
                    Member.Administrator.CacheAdminInfo(admin);
                    Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 解锁成功", "解锁成功 [用户名=" + name + "] ");
                    JsonResult(context, 1, "解锁成功");
                }
                else
                {
                    Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 解锁失败", "解锁失败 [用户名=" + name + "] 账户验证成功 , 但是账户状态已经异常 , 可能是由于锁定过程中被修改了账户状态导致", model);
                    JsonResult(context, 0, "您的账号状态异常 , 请联系您的管理员");
                }
            }
            else
            {
                Evan.SystemLog.SysLog.AddSysLog("管理员 [" + name + "] 登录失败", "登录失败 [用户名=" + name + "] 账号密码不匹配", model);
                JsonResult(context, 0, "账号密码不匹配");
            }

        }


        #region 获取管理员信息
        /// <summary>
        /// 获取管理员是否登录
        /// </summary>
        /// <returns></returns>
        public bool IsAdminLogin()
        {
            return Evan.Member.Administrator.IsAdminLogin();
        }
        /// <summary>
        /// 获取管理员信息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetAdminInfoFromCache()
        {
            if (Evan.Member.Administrator.IsAdminLogin())
            {
                return Evan.Member.Administrator.GetAdminInfoFromCache(); //(Dictionary<string, object>)Evan.Common.CacheHelp.GetValue("admin-" + Common.CommFun.ReturnSessionID());
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获取管理员ID
        /// </summary>
        /// <returns></returns>
        public string GetAdminId()
        {
            return Evan.Member.Administrator.GetAdminId();
            //var AdminInfo = GetAdminInfoFromCache();
            //if (AdminInfo != null)
            //{
            //    return AdminInfo["Id"].ToString();
            //}
            //else
            //{
            //    return "";
            //}
        }
        #endregion

        

        #region  新版自动添加伪静态
        /// <summary>
        /// 生成URL规则 , 自动寻找写进去的栏目配置参数 , 参数要求和数据库字段一致 除了Page以外
        /// 参数的首字母必须大写
        /// </summary>
        /// <param name="ClassId">栏目ID</param>
        /// <param name="RewriteStr">栏目中设置的重写规则Url</param>
        /// <param name="TemplateStr">栏目对应的模板页面</param>
        /// <returns></returns>
        public Evan.Model.SysModel.RewriteUrlModel MakeRewriteUrl(int ClassId, string RewriteStr, string TemplateStr)
        {
            try
            {

                MatchCollection mc = Regex.Matches(RewriteStr, "{(.*?)}");
                List<string> ArgList = new List<string>();
                foreach (Match item in mc)
                {
                    ArgList.Add(item.Value.TrimStart('{').TrimEnd('}'));
                }
                Evan.Model.SysModel.RewriteUrlModel ru = new Evan.Model.SysModel.RewriteUrlModel();

                ru.reg = RewriteStr;
                ru.url = TemplateStr + "?Channel=" + ClassId;

                XmlDocument xml = new XmlDocument();
                xml.Load(HttpContext.Current.Server.MapPath("~/App_Data/SysConfig/ext.config"));

                //string nodeVal = "";
                int count = 1;
                foreach (var item in ArgList)
                {
                    ru.reg = ru.reg.Replace("{" + item + "}", xml.SelectSingleNode("/root/extended[@type='rewrite-field-reg']/item[@key='" + item + "']").Attributes["val"].Value);
                    ru.url = ru.url + "&" + item + "={" + count + "}";
                    count = count + 1;
                }
                //string nodelist = xml.Read("/root/extended[@key="++"]");

                return ru;
            }
            catch (Exception ex)
            {
                Evan.SystemLog.MemLog.AddExLog2("生成伪静态条目出错", null, ex.ToString());
                throw;
            }
        }

        /// <summary>
        /// 在模板表中查找对应的数据
        /// </summary>
        /// <param name="list">模板表的数据 list</param>
        /// <param name="Id">模板id</param>
        /// <returns></returns>
        private dynamic FindOneTemplate(List<dynamic> list, int Id)
        {
            return list.Find((dynamic r) => r.Id == Id);
        }

        /// <summary>
        /// 新版移除节点 仅供内部调用
        /// </summary>
        /// <param name="ChannelId"></param>
        public void AutoRewriteDel(int ChannelId)
        {
            string xmlPath = HttpContext.Current.Server.MapPath("~/App_Data/SysConfig/url_system.config");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            XmlNodeList rootChild = xmlDoc.SelectSingleNode("root").ChildNodes;

            foreach (XmlNode node in rootChild)
            {
                XmlElement xe = (XmlElement)node;
                if (xe.GetAttribute("channel") == ChannelId.ToString())
                {
                    xmlDoc.SelectSingleNode("root").RemoveChild(node); //移除当前节点
                }
            }
            xmlDoc.Save(xmlPath);
        }
        /// <summary>
        /// 新版自动进行伪静态处理,根据当前栏目处理伪静态规则
        /// 里面包含的 删除之前的伪静态, 调用的时候不用先删除之前的伪静态 直接调用即可
        /// </summary>
        /// <param name="context"></param>
        /// <param name="ChannelModel">当前栏目的dynamic</param>
        public void AutoRewriteAdd(HttpContext context, dynamic ChannelModel)
        {
            //进来第一件事就是删除之前的伪静态 , 防止栏目类型改变后伪静态没有及时删除 , 
            if (Model.ConvertModel.HasKey(ChannelModel,"Id"))
            {
                //存在ID 说明是编辑  , 否则是添加
                AutoRewriteDel(Convert.ToInt32(ChannelModel.Id));
            }
            //if (Convert.ToInt32(ChannelModel.PageType) == 0) //综合页直接返回
            //{
            //    return;
            //}
            //标识是否生成伪静态规则
            bool CreateReWriteRule = false;

            #region 栏目伪静态处理
            string xmlPath = context.Server.MapPath("~/App_Data/SysConfig/url_system.config");

            string TemplateRootPath = "/templates/";


            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            XmlNode root = xmlDoc.SelectSingleNode("root"); //查找 root
            XmlElement rewrite = xmlDoc.CreateElement("rewrite"); //创建一个rewrite节点
            rewrite.SetAttribute("channel", ChannelModel.Id.ToString());//设置rewrite节点channel属性   
            rewrite.SetAttribute("path", ChannelModel.WebPath);//设置rewrite节点path属性   

            List<dynamic> AllTemplateList = new Evan.DataBase.DbOperat("Template").GetList("States=1 and TemplateCategory='Template'");
            
            int ChannelId = Convert.ToInt32(ChannelModel.Id);
            string ChanneWebPath = ChannelModel.WebPath;

            string RewriteDefault = ChannelModel.RewriteDefault;
            string RewriteList = ChannelModel.RewriteList;
            string RewriteDetail = ChannelModel.RewriteDetail;
            string RewriteSinglePage = ChannelModel.RewriteSinglePage;
            
            
            int TemplateDefault = Convert.ToInt32(ChannelModel.TemplateDefault);
            int TemplateList = Convert.ToInt32(ChannelModel.TemplateList);
            int TemplateDetail = Convert.ToInt32(ChannelModel.TemplateDetail);
            int TemplateSinglePage = Convert.ToInt32(ChannelModel.TemplateSinglePage);

            dynamic _temp = new Evan.Model.DynamicModel();

           string TemplateDefaultPath = "";
           string TemplateListPath = "";
           string TemplateDetailPath = "";
           string TemplateSinglePagePath = "";

           //生成的时候需要 满足2个条件  1,选择了栏目模板 2,填写了url规则

           #region 综合页伪静态处理
           if (TemplateDefault > 0 && !string.IsNullOrEmpty(RewriteDefault))
            {
                CreateReWriteRule = true;
                //有综合页 生成综合页重写信息

                _temp = FindOneTemplate(AllTemplateList, TemplateDefault);
                TemplateDefaultPath = TemplateRootPath + (string.IsNullOrEmpty(_temp.TemplatePath) ? "" : _temp.TemplatePath + "/") + _temp.TemplateName + ".aspx";

                //需要生成 /webpath/ , /webpath , /webpath/pagename.html  3个

                #region 创建综合页重写规则
                //创建引导页的重写规则1
                XmlElement Default1 = xmlDoc.CreateElement("item");
                Default1.SetAttribute("reg", "^" + ChanneWebPath.TrimEnd('/') + "$");
                Default1.SetAttribute("url", TemplateDefaultPath + "?Channel=" + ChannelId);
                rewrite.AppendChild(Default1);//添加到节点中   
                //创建引导页的重写规则2
                XmlElement Default2 = xmlDoc.CreateElement("item");
                Default2.SetAttribute("reg", "^" + ChanneWebPath + "$");
                Default2.SetAttribute("url", TemplateDefaultPath + "?Channel=" + ChannelId);
                rewrite.AppendChild(Default2);//添加到节点中 
                #endregion

                if (RewriteDefault.IndexOf('{') > -1 && RewriteDefault.IndexOf('}') > -1)
                {
                    //有参数的
                    //创建引导页的重写规则3
                    XmlElement Default3 = xmlDoc.CreateElement("item");
                    Evan.Model.SysModel.RewriteUrlModel ru = MakeRewriteUrl(ChannelId, RewriteDefault, TemplateDefaultPath);
                    Default3.SetAttribute("reg", "^" + ChanneWebPath + ru.reg +"$");
                    Default3.SetAttribute("url", ru.url);
                    rewrite.AppendChild(Default3);//添加到节点中 
                }
                else {
                    //创建引导页的重写规则3
                    XmlElement Default3 = xmlDoc.CreateElement("item");
                    Default3.SetAttribute("reg", "^" + ChanneWebPath + RewriteDefault + "$");
                    Default3.SetAttribute("url", TemplateDefaultPath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(Default3);//添加到节点中 
                }
            }
           #endregion

           #region 列表页伪静态处理
           if (TemplateList > 0 && !string.IsNullOrEmpty(RewriteList))
            {
                CreateReWriteRule = true;
                //有列表页 生成列表页重写信息

                _temp = FindOneTemplate(AllTemplateList, TemplateList);
                TemplateListPath = TemplateRootPath + (string.IsNullOrEmpty(_temp.TemplatePath) ? "" : _temp.TemplatePath + "/") + _temp.TemplateName + ".aspx";

                //需要生成 /webpath/ , /webpath , /webpath/pagename.html  3个

                //创建首页重写规则1
                XmlElement Index1 = xmlDoc.CreateElement("item");
                Index1.SetAttribute("reg", "^" + ChanneWebPath.TrimEnd('/') + "$");
                Index1.SetAttribute("url", TemplateListPath + "?Channel=" + ChannelId);
                rewrite.AppendChild(Index1);//添加到节点中   
                //创建首页重写规则2
                XmlElement Index2 = xmlDoc.CreateElement("item");
                Index2.SetAttribute("reg", "^" + ChanneWebPath + "$");
                Index2.SetAttribute("url", TemplateListPath + "?Channel=" + ChannelId);
                rewrite.AppendChild(Index2);//添加到节点中   
                //创建首页重写规则3
                XmlElement Index3 = xmlDoc.CreateElement("item");
                Index3.SetAttribute("reg", "^" + ChanneWebPath + "index.html$");
                Index3.SetAttribute("url", TemplateListPath + "?Channel=" + ChannelId);
                rewrite.AppendChild(Index3);//添加到节点中

                if (RewriteList.IndexOf('{') > -1 && RewriteList.IndexOf('}') > -1)
                {
                    //有参数的
                    XmlElement Index4 = xmlDoc.CreateElement("item");
                    Evan.Model.SysModel.RewriteUrlModel ru = MakeRewriteUrl(ChannelId, RewriteList, TemplateListPath);
                    Index4.SetAttribute("reg", "^" + ChanneWebPath + ru.reg + "$");
                    Index4.SetAttribute("url", ru.url);
                    rewrite.AppendChild(Index4);//添加到节点中
                }
                //else {
                //    XmlElement Index4 = xmlDoc.CreateElement("item");
                //    Index4.SetAttribute("reg", "^" + ChanneWebPath + "index.html$");
                //    Index4.SetAttribute("url", TemplateListPath + "?channel=" + ChannelId);
                //    rewrite.AppendChild(Index4);//添加到节点中
                //}
            }
           #endregion

           #region 详细页伪静态处理
           if (TemplateDetail > 0 && !string.IsNullOrEmpty(RewriteDetail))
            {
                CreateReWriteRule = true;
                //有详细页 生成详细页重写信息

                _temp = FindOneTemplate(AllTemplateList, TemplateDetail);
                TemplateDetailPath = TemplateRootPath + (string.IsNullOrEmpty(_temp.TemplatePath) ? "" : _temp.TemplatePath + "/") + _temp.TemplateName + ".aspx";

                if (RewriteDetail.IndexOf('{') > -1 && RewriteDetail.IndexOf('}') > -1)
                {
                    //有参数的
                    XmlElement Detail1 = xmlDoc.CreateElement("item");
                    Evan.Model.SysModel.RewriteUrlModel ru = MakeRewriteUrl(ChannelId, RewriteDetail, TemplateDetailPath);
                    Detail1.SetAttribute("reg", "^" + ChanneWebPath + ru.reg + "$");
                    Detail1.SetAttribute("url", ru.url);
                    rewrite.AppendChild(Detail1);//添加到节点中
                }
                else
                {
                    //没有参数的

                    //创建详细页的重写规则1
                    XmlElement Detail1 = xmlDoc.CreateElement("item");
                    Detail1.SetAttribute("reg", "^" + ChanneWebPath.TrimEnd('/') + "$");
                    Detail1.SetAttribute("url", TemplateDefaultPath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(Detail1);//添加到节点中   
                    //创建详细页的重写规则2
                    XmlElement Detail2 = xmlDoc.CreateElement("item");
                    Detail2.SetAttribute("reg", "^" + ChanneWebPath + "$");
                    Detail2.SetAttribute("url", TemplateDefaultPath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(Detail2);//添加到节点中 
                    //创建详细页的重写规则3
                    XmlElement Detail3 = xmlDoc.CreateElement("item");
                    Detail3.SetAttribute("reg", "^" + ChanneWebPath + "index.html$");
                    Detail3.SetAttribute("url", TemplateDetailPath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(Detail3);//添加到节点中
                }
            }
           #endregion

           #region 单页伪静态处理
           if (TemplateSinglePage > 0 && !string.IsNullOrEmpty(RewriteSinglePage))
            {
                CreateReWriteRule = true;
                //有单页面 生成单页面重写信息

                _temp = FindOneTemplate(AllTemplateList, TemplateSinglePage);
                TemplateSinglePagePath = TemplateRootPath + (string.IsNullOrEmpty(_temp.TemplatePath) ? "" : _temp.TemplatePath + "/") + _temp.TemplateName + ".aspx";

                //需要生成 /webpath/ , /webpath , /webpath/pagename.html  3个

                if (RewriteSinglePage.IndexOf('{') > -1 && RewriteSinglePage.IndexOf('}') > -1)
                {
                    //有参数的
                    XmlElement SinglePage1 = xmlDoc.CreateElement("item");
                    Evan.Model.SysModel.RewriteUrlModel ru = MakeRewriteUrl(ChannelId, RewriteSinglePage, TemplateSinglePagePath);
                    SinglePage1.SetAttribute("reg", "^" + ChanneWebPath + ru.reg + "$");
                    SinglePage1.SetAttribute("url", ru.url);
                    rewrite.AppendChild(SinglePage1);//添加到节点中 
                }
                else { 
                    //没有参数的

                    //创建单页的重写规则1
                    XmlElement SinglePage1 = xmlDoc.CreateElement("item");
                    SinglePage1.SetAttribute("reg", "^" + ChanneWebPath.TrimEnd('/') + "$");
                    SinglePage1.SetAttribute("url", TemplateSinglePagePath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(SinglePage1);//添加到节点中   
                    //创建单页的重写规则2
                    XmlElement SinglePage2 = xmlDoc.CreateElement("item");
                    SinglePage2.SetAttribute("reg", "^" + ChanneWebPath + "$");
                    SinglePage2.SetAttribute("url", TemplateSinglePagePath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(SinglePage2);//添加到节点中 
                    //创建单页的重写规则3
                    XmlElement SinglePage3 = xmlDoc.CreateElement("item");
                    SinglePage3.SetAttribute("reg", "^" + ChanneWebPath + "index.html$");
                    SinglePage3.SetAttribute("url", TemplateSinglePagePath + "?Channel=" + ChannelId);
                    rewrite.AppendChild(SinglePage3);//添加到节点中
                }
            }
            #endregion


            // #region 综合链接的伪静态处理  清空 rewrite 然后重新加链接
            // if (Convert.ToInt32(ChannelModel.PageType) == 99)
            // {
            //     rewrite.RemoveAll();

            //     //创建综合链接的重写规则1
            //     XmlElement IntegratedLink1 = xmlDoc.CreateElement("item");
            //     IntegratedLink1.SetAttribute("reg", "^" + ChanneWebPath.TrimEnd('/') + "$");
            //     IntegratedLink1.SetAttribute("url", TemplateSinglePagePath + "?Channel=" + ChannelId);
            //     rewrite.AppendChild(IntegratedLink1);//添加到节点中   
            //     //创建综合链接的重写规则2
            //     XmlElement IntegratedLink2 = xmlDoc.CreateElement("item");
            //     IntegratedLink2.SetAttribute("reg", "^" + ChanneWebPath + "$");
            //     IntegratedLink2.SetAttribute("url", TemplateSinglePagePath + "?Channel=" + ChannelId);
            //     rewrite.AppendChild(IntegratedLink2);//添加到节点中 
            //     //创建综合链接的重写规则3
            //     XmlElement IntegratedLink3 = xmlDoc.CreateElement("item");
            //     IntegratedLink3.SetAttribute("reg", "^" + ChanneWebPath + "index.html$");
            //     IntegratedLink3.SetAttribute("url", TemplateSinglePagePath + "?Channel=" + ChannelId);
            //     rewrite.AppendChild(IntegratedLink3);//添加到节点中

            // }
            //#endregion
            
            if (CreateReWriteRule)
            {
                root.AppendChild(rewrite);//添加到<rewrite>节点中   
                xmlDoc.Save(xmlPath);
            }
            #endregion
        }
        #endregion

        #region 保存栏目的时候 , 根据当前系统状态自动生成栏目字段 , 后面这里需要挪到底层中去
        /// <summary>
        /// 保存栏目的时候 , 根据当前系统状态自动生成栏目字段 , 后面这里需要挪到底层中去
        /// <para>在当前栏目保存的时候写字段 , 需要判断当前系统是否套模板的系统 </para>
        /// <para>如果脱离了套模板的系统则里面的不执行, 如果是套模板的则要在栏目保存的时候检测模板有没有改动   如果有改动 , 提示覆盖字段</para>
        /// </summary>
        /// <param name="ClassId"></param>
        public void AutoFieldByTemplate(int ClassId)
        {
            //只有在套模板的里面存在
            if (Evan.Common.CommFun.GetAppSetting("IsModuleSystem") == "1" && ClassId > 0)
            {
                DataBase.DbOperat BLL_Module = new Evan.DataBase.DbOperat("Module");
                dynamic curChannelModel = new Evan.DataBase.DbOperat("Channel").GetModel(ClassId);

                List<dynamic> FieldList = new List<dynamic>(); //存起来所有的字段

                List<dynamic> Fields = new List<dynamic>(); //单个模板的字段查询容器
                List<string> SqlCommads = new List<string>(); //将当前模块里面的sql语句拿出来存着
                string TemplateIds = "";
                //栏目用到的模板全部检查一下
                if (Convert.ToInt32(curChannelModel.TemplateSinglePage) > 0)
                {
                    TemplateIds += curChannelModel.TemplateSinglePage + ",";
                }
                if (Convert.ToInt32(curChannelModel.TemplateList) > 0)
                {
                    TemplateIds += curChannelModel.TemplateList + ",";
                }
                if (Convert.ToInt32(curChannelModel.TemplateDetail) > 0)
                {
                    TemplateIds += curChannelModel.TemplateDetail + ",";
                }
                if (Convert.ToInt32(curChannelModel.TemplateDefault) > 0)
                {
                    TemplateIds += curChannelModel.TemplateDefault + ",";
                }
                TemplateIds = TemplateIds.Trim(',');
                if (!string.IsNullOrEmpty(TemplateIds))
                {
                    //先把所有的字段拿出来放一边
                    Fields = new Evan.DataBase.DbOperat("Module").GetList("IsInclude=0 and TemplateId in (" + TemplateIds + ")", "Id asc");
                    foreach (var item in Fields)
                    {
                        if (!string.IsNullOrEmpty(item.Fields))
                        {
                            //把里面的字段信息取出来解析
                            List<dynamic> fList = Evan.Common.JsonHelper.JsonToList<dynamic>(item.Fields);
                            foreach (var item2 in fList)
                            {
                                FieldList.Add(item2);
                            }
                            //FieldList.Add(item.Fields);
                        }
                    }
                    //拿出对应的SQL语句

                    List<dynamic> Fields_SqlCmd = new Evan.DataBase.DbOperat("Module").GetList("TemplateId in (" + TemplateIds + ")", "Id asc");
                    Evan.DataBase.MsSql.DbHelper ExecSqlCmd = new Evan.DataBase.MsSql.DbHelper();
                    //Evan.SystemLog.MemLog.AddExLog2("开始准备拿SQLCMD", null, "开始准备拿SQLCMD");
                    foreach (var item in Fields_SqlCmd)
                    {
                        if (item.Attr == "include")
                        {
                            //如果是引用模块的话 , 拿到当前引用模板的Id (当前的IsInclude)  , 用这个IsInclude , 去在Module表中查找
                            dynamic IncludeModule = BLL_Module.GetModel_1("TemplateId=@TemplateId and States = 1", item.IsInclude);
                            //Evan.SystemLog.MemLog.AddExLog2("开始准备拿引用模块SQLCMD", null, "开始准备拿引用模块SQLCMD");
                            if (IncludeModule != null)
                            {
                                //Evan.SystemLog.MemLog.AddExLog2("拿到引用模块SQLCMD-0", null, "拿到引用模块SQLCMD-0");
                                item.Set("SqlCommad", IncludeModule.SqlCommad);
                                //Evan.SystemLog.MemLog.AddExLog2("拿到引用模块SQLCMD", null, "拿到引用模块SQLCMD");
                            }
                        }
                        if (!string.IsNullOrEmpty(item.SqlCommad))
                        {
                            try
                            {
                                int isSuccess = ExecSqlCmd.ExecteNonQuery(System.Data.CommandType.Text, item.SqlCommad.Replace("@ClassId", ClassId.ToString()));
                                if (isSuccess < 1)
                                {
                                    Evan.SystemLog.MemLog.AddExLog2("添加栏目时执行Sql语句无效", new Dictionary<string, string>().Add("SQL语句为", item.SqlCommad.Replace("@ClassId", ClassId)), "执行SQL失败");
                                }
                            }
                            catch (Exception ex)
                            {
                                Evan.SystemLog.MemLog.AddExLog2("添加栏目时执行Sql语句出错", new Dictionary<string, string>().Add("SQL语句为", item.SqlCommad.Replace("@ClassId", ClassId)), "出错信息 : " + ex.ToString());
                            }
                        }
                    }
                    //从数据库物理删除当前栏目的字段 , 重新添加
                    new Evan.DataBase.DbOperat("Fields").Delete_1("ClassId=@ClassId and States=1", ClassId);
                    //将各个JSON解析成单个Fields
                    //拿完所有字段 然后遍历所有字段  
                    // 1,在数据库添加字段  2,在栏目里添加这个字段
                    dynamic oneField = new Evan.Model.DynamicModel();
                    foreach (var item in FieldList)
                    {
                        
                        oneField = new Evan.Model.DynamicModel();
                        oneField.Set("AddTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        oneField.Set("AddUser", Evan.Member.Administrator.GetAdminId());
                        oneField.Set("EditTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        oneField.Set("EditUser", Evan.Member.Administrator.GetAdminId());
                        
                        oneField.Set("ClassId", ClassId);

                        
                        IDictionary<string, object> dic = item as IDictionary<string, object>;
                        if (dic.ContainsKey("Content"))
                        {
                            oneField.Set("Content", item["Content"]);
                        }
                        else
                        {
                            //如果字段不存在
                            oneField.Set("Content", "");
                        }

                        oneField.Set("DefaultValue", item["DefaultValue"]);
                        oneField.Set("FieldName", item["FieldName"]);
                        oneField.Set("FieldSize", item["FieldSize"]);
                        oneField.Set("FieldType", item["FieldType"]);
                        oneField.Set("FieldVerify", item["FieldVerify"]);
                        oneField.Set("IsList", "0");
                        oneField.Set("IsShow", "1");
                        oneField.Set("IsSubChannel", "0");
                        oneField.Set("MaxLength", "0");
                        oneField.Set("Notice", item["Notice"]);
                        oneField.Set("PlaceHoder", item["PlaceHoder"]);
                        oneField.Set("ShareId", "0");
                        oneField.Set("SortId", "100");
                        oneField.Set("States", "1");
                        oneField.Set("TemplateType", "");
                        oneField.Set("Title", item["FieldTitle"]);
                        AddFieldToDb(oneField);
                        //FieldName
                        //oneField.Set()
                        //oneField.FieldDefault
                    }

                }
                //如果是套模板的项目 , 给数据库添加完字段后重启下程序 , 达到让字段生效的目的
                Evan.Common.CommFun.ReStartCurWeb();
            }
        }
        private int AddFieldToDb(dynamic model)
        {
            //dynamic model = Evan.Model.ConvertModel.ConvertToDynamic(GetParam("model"));
            string table = "Fields";
            //拿到classid 用classid获取栏目信息 获取pagetype 获取表名称
            string classid = model.ClassId.ToString();
            //获取到对应的栏目
            dynamic channel = new Evan.DataBase.DbOperat("Channel").GetModel(int.Parse(classid));
            string channel_tablename = Evan.Template.TemplateHelper.GetTableNameByPageType(Convert.ToInt32(channel.PageType));
            //如果拿到的表名称是空的 那就返回错误
            if (string.IsNullOrEmpty(channel_tablename))
            {
                return -3;
            }
            //先检查字段名是否存在
            Evan.DataBase.DbOperat Db = new Evan.DataBase.DbOperat(channel_tablename);
            bool isExist = Db.IsExistField(model.FieldName);
            if (!isExist)
            {
                //不存在开始添加  添加分两步  1 添加一行数据到field表  2 添加字段到对应表
                Evan.Model.SysModel.FieldModel FieldModel = Evan.Model.ConvertModel.ConvertToFieldModel(model, channel_tablename);
                bool IsOk = Db.AddFieldToTable(FieldModel);
                if (IsOk)
                {

                    model.Set("AddUser", GetAdminId());
                    model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                    //model.Set("FieldVerify", model.FieldVerify.ToString().Trim(','));
                    return Db.InsertReturnId(model, table);
                }
                else
                {
                    return -2;
                }
            }
            else
            {
                try
                {
                    //如果存在当前字段  如果是处于被删除的状态下  那就激活这个字段 并更新当前的属性值到该表
                    dynamic field = new Evan.DataBase.DbOperat(table).GetModel_1("ClassId=" + classid + " and FieldName='" + model.FieldName + "'");
                    if (field == null)
                    {
                        model.Set("AddUser", GetAdminId());
                        model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                        return Db.InsertReturnId(model, table);
                    }
                    else
                    {
                        //不为空 说明是被锁定后修改
                        model.Set("Id", field.Id);
                        model.Set("States", "1");
                        model.Set("AddUser", GetAdminId());
                        model.Set("AddTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                        bool isok = UpdateModel(table, model);
                        Evan.SystemLog.MemLog.AddExLog2("已经存在字段 , 需将字段显示并重新赋值", null, "操作状态 : " + isok.ToString());
                        return isok ? 1 : 0;

                    }
                }
                catch (Exception ex)
                {
                    Evan.SystemLog.MemLog.AddExLog2("添加字段失败 , 调用方法名 : " + ex.TargetSite.Name, null, ex.ToString());
                    return -1;
                }
            }
        }
        #endregion


        #region 生成SiteMap
        /// <summary>
        /// 生成SiteMap , JsonResult 返回 1 成功  -1 失败
        /// </summary>
        /// <param name="context"></param>
        public void CreateSiteMap(HttpContext context)
        {
            bool IsOk = Template.CreateSiteMap.Create();
            JsonResult(context, IsOk ? 1 : -1, "生成SiteMap");
        }
        #endregion

        #region  生成静态页
        //先获取当前要生成的列表
        //再一条一条提交生成
        /// <summary>
        /// 获取所有的链接 返回到前端
        /// </summary>
        /// <param name="context"></param>
        public void GetUrlList(HttpContext context)
        {
            try
            {
                //是否有栏目ID  如果有栏目ID  那只是生成栏目的静态页
                string channel = Evan.Common.CommFun.GetParams("channel");
                string urlStr = "";
                if (!string.IsNullOrEmpty(channel))
                {
                    //生成某个栏目静态页
                    List<string> urls = new Template.Base().GetUrlList(Convert.ToInt32(channel));
                    urlStr = string.Join(",", urls.ToArray());
                }
                else
                {
                    List<string> urls = new Template.Base().GetUrlList();
                    urlStr = string.Join(",", urls.ToArray());
                }
                JsonResult(context, 1, urlStr);
            }
            catch (Exception ex)
            {
                Evan.SystemLog.MemLog.AddExLog2("请求获取URL列表的时候出错", null, ex.ToString());
                JsonResult(context, 0, "获取URL列表失败");
            }
        }

        /// <summary>
        /// 生成当前页面 返回生成结果
        /// site 当前站点URL
        /// url 需要生成的URL
        /// folder 需要将页面生成到那个页面
        /// </summary>
        /// <param name="context"></param>
        public void CreatePage(HttpContext context)
        {
            string site = Evan.Common.CommFun.GetParams("site");
            string url = Evan.Common.CommFun.GetParams("page");
            string folder = Evan.Common.CommFun.GetParams("folder");
            bool IsOk = Evan.Template.CreateStaticPage.Create(site, url, folder);
            JsonResult(context, IsOk ? 1 : -1, "生成静态页");
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}
